home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / c / TinyGL.lha / tinygl / src / oscontext.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-07  |  2.0 KB  |  85 lines

  1. #include <GL/oscontext.h>
  2. #include "zbuffer.h"
  3. #include "zgl.h"
  4. #include <GL/gl.h>
  5. #include <stdlib.h>
  6. #include <assert.h>
  7.  
  8. static int buffercnt = 0;
  9.  
  10. ostgl_context *
  11. ostgl_create_context(const int xsize,
  12.                      const int ysize,
  13.                      const int depth,
  14.                      void **framebuffers,
  15.                      const int numbuffers)
  16. {
  17.   ostgl_context *context;
  18.   int i;
  19.   ZBuffer *zb;
  20.    
  21.   assert(depth == 16); /* support for other depths must include bpp 
  22.                           convertion */
  23.   assert(numbuffers >= 1);
  24.   
  25.   context = gl_malloc(sizeof(ostgl_context));
  26.   assert(context);
  27.   context->zbs = gl_malloc(sizeof(void*)*numbuffers);
  28.   context->framebuffers = gl_malloc(sizeof(void*)*numbuffers);
  29.   
  30.   assert(context->zbs != NULL && context->framebuffers != NULL);
  31.   
  32.   for (i = 0; i < numbuffers; i++) {
  33.     context->framebuffers[i] = framebuffers[i];
  34.     zb = ZB_open(xsize, ysize, ZB_MODE_5R6G5B, 0, NULL, NULL, framebuffers[i]);
  35.     if (zb == NULL) {
  36.       fprintf(stderr, "Error while initializing Z buffer\n");
  37.       exit(1);
  38.     }
  39.     context->zbs[i] = zb;
  40.   }
  41.   if (++buffercnt == 1) {
  42.     glInit(context->zbs[0]);
  43.   }
  44.   context->xsize = xsize;
  45.   context->ysize = ysize;
  46.   context->numbuffers = numbuffers;
  47.   return context;
  48. }
  49.  
  50. void
  51. ostgl_delete_context(ostgl_context *context)
  52. {
  53.   int i;
  54.   for (i = 0; i < context->numbuffers; i++) {
  55.     ZB_close(context->zbs[i]);
  56.   }
  57.   gl_free(context->zbs);
  58.   gl_free(context->framebuffers);
  59.   gl_free(context);
  60.   
  61.   if (--buffercnt == 0) {
  62.     glClose();
  63.   }
  64. }
  65.  
  66. void
  67. ostgl_make_current(ostgl_context *oscontext, const int idx)
  68. {
  69.   GLContext *context = gl_get_context();
  70.   assert(idx < oscontext->numbuffers);
  71.   context->zb = oscontext->zbs[idx];
  72. }
  73.  
  74. void
  75. ostgl_resize(ostgl_context *context,
  76.              const int xsize,
  77.              const int ysize,
  78.              void **framebuffers)
  79. {
  80.   int i;
  81.   for (i = 0; i < context->numbuffers; i++) {
  82.     ZB_resize(context->zbs[i], framebuffers[i], xsize, ysize);
  83.   }
  84. }
  85.